/*
 * Copyright 2011-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.platform.framework.mybatis.autoconfigure;

import java.util.Properties;

import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MyBatis 扩展配置：创建 MybatisAutoConfiguration 需要所需的 Bean
 *
 * @author liym
 * @see org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration#MybatisAutoConfiguration
 * @see org.apache.ibatis.builder.xml.XMLConfigBuilder#parse
 * @since 2019-03-06 09:51 新建
 */
@AutoConfigureBefore(MybatisAutoConfiguration.class)
@Configuration
public class MyBatisExtConfiguration {

    public MyBatisExtConfiguration() {
    }

    /**
     * MyBatis 之 databaseIdProvider 多数据库支持
     *
     * @return {@link DatabaseIdProvider}
     * @see org.springframework.beans.factory.ObjectProvider#getIfAvailable()
     * @see org.apache.ibatis.builder.xml.XMLStatementBuilder#parseStatementNode
     * @since 2019-03-06 09:53
     */
    @Bean
    public DatabaseIdProvider databaseIdProvider() {
        Properties properties = new Properties();
        properties.put("MySQL", "mysql");
        properties.put("PostgreSQL", "postgres");
        properties.put("Oracle", "oracle");
        properties.put("DB2", "db2");

        DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        databaseIdProvider.setProperties(properties);
        return databaseIdProvider;
    }

}
